#include"StdAfx.h"
#include"Tsys.h"

bool TCreateLink(TString _appPath, TString _cmdLine, TString _SavePath)
{
	LRESULT hr = CoInitialize(NULL);
	IShellLink* pShellLink = NULL;
	IPersistFile* pPersistFile = NULL;
	if (SUCCEEDED(hr))
	{		
		hr = CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC, IID_IShellLink, (void**)&pShellLink);
		if (SUCCEEDED(hr))
		{
			pShellLink->SetPath(_appPath.GetData());
			int pos = _appPath.ReverseFind(_T('\\'));
			pShellLink->SetWorkingDirectory(_appPath.Left(pos));
			pShellLink->SetArguments(_cmdLine.GetData());			
			hr = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
			if (SUCCEEDED(hr))
			{
				hr=pPersistFile->Save(_SavePath, false);
				if (SUCCEEDED(hr))
				{
					pPersistFile->Release();
					pShellLink->Release();
					CoUninitialize();
					return true;
				}
			}
		}
	}
	pPersistFile->Release();
	pShellLink->Release();
	CoUninitialize();
	return false;
}

bool TOpenBrowseFolder(TString& _txt)
{
	BROWSEINFO bi = {0};
	LPITEMIDLIST lpid = SHBrowseForFolder(&bi);
	if (lpid==nul)
	{
		return false;
	}
	
	TCHAR str[MAX_PATH];
	SHGetPathFromIDList(lpid, str);
	_txt.Assign(str);
	return true;
}
